package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.Tag;
import cn.kgc.springcloud.service.TagService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author 课工场
 * @date 2023/10/19
 * @description
 */
@RestController
@RequestMapping("tag")
public class TagController {

    @Resource
    private TagService tagService;

    @GetMapping
    public List<Tag> getList(){

        return tagService.list();

    }


    @DeleteMapping("{id}")
    public Boolean deleteTag(@PathVariable("id") Integer id){

        return  tagService.removeById(id);
    }

    @PostMapping
    public Tag  addTag(@RequestBody Tag tag){

        tag.setCreatedate(new Date());
        tagService.save(tag);

        return tag;
    }


    @GetMapping("{id}")
    public Tag getById(@PathVariable("id") Integer id){

         return tagService.getById(id);
    }
}
